package com.yaozheng.vocationaltraining.service.impl.experience;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.experience.IMyExperienceView;
import com.yaozheng.vocationaltraining.service.experience.MyExperienceService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

/**
 * 我的经验值
 */
@EBean
public class MyExperienceServiceImpl implements MyExperienceService {
    IMyExperienceView iMyExperienceView;

    @Override
    public void init(IMyExperienceView iMyExperienceView) {
        this.iMyExperienceView = iMyExperienceView;
    }

    @Background
    @Override
    public void experienceData() {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/user/experience",
                    iMyExperienceView.getToken(), new BaseView(iMyExperienceView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iMyExperienceView.experienceDataSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iMyExperienceView.experienceDataError(error);
                        }
                    });
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iMyExperienceView.isResponseResult()) {
                iMyExperienceView
                        .experienceDataError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
